/*
 * @Description: 客户订单属性DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2020-12-28 20:03:25
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-03-18 15:13:17
 */
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';

import intl from 'utils/intl';
// import { DataSet } from 'choerodon-ui/pro/lib';

const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;;

// const areaOptions = new DataSet({
//     selection: 'single' as DataSetSelection,
//     autoQuery: true,
//     paging: false,
//     parentField: 'parentId',
//     idField: 'id',
//     transport: {
//         read: (config) => {
//             return {
//                 ...config,
//                 url: `/hitf/v1/dji-external-interface/get-area-region`,
//                 method: 'GET',
//                 transformResponse: value => {
//                     const reqData = JSON.parse(value);
//                     // 解决大区域没有 regionName regionId显示不了的问题
//                     const newList = reqData.map(item => {
//                         return {
//                             ...item,
//                             regionName: item.regionName || item.areaName,
//                             regionId: item.regionId || item.areaId,
//                         };
//                     });
//                     // 按名字字母进行排序
//                     newList.sort((a, b) => { return a.regionName.charCodeAt(0) - b.regionName.charCodeAt(0); });
//                     return newList;
//                 },
//             };
//         },
//     },
// });

// const customerOptions = new DataSet({
//     selection: 'single' as DataSetSelection,
//     autoQuery: true,
//     paging: false,
//     transport: {
//         read: (config) => {
//             return {
//                 ...config,
//                 url: `/hitf/v1/dji-external-interface/list-customer`,
//                 method: 'POST',
//             };
//         },
//     },
// });


const customerOrderAttributeListDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            // 封装大区小区参数
            const { data } = config;
            let submitObj = {
                ...config.data,
            };
            if (data && data.area) {
                submitObj = {
                    ...config.data,
                    bigArea: data.area[0],
                    smallArea: data.area[1],
                };
            };
            delete submitObj.area;
            return {
                ...config,
                data: submitObj,
                url: `${O2_OM}/v1/customer-order-configs`,
                method: 'get',
            };
        },
        create: config => {
            return {
                ...config,
                data: config.data[0],
                url: `${O2_OM}/v1/customer-order-configs`,
                method: 'post',
            };
        },
        update: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/customer-order-configs`,
                method: 'put',
            };
        },
    },
    fields: [
        // {
        //     name: 'customerTradeToken',
        //     type: FieldType.string,
        //     label: intl.get('dji.otc.om.view.field.orderType').d('交易身份编码'),
        //     required: true,
        // },
        // {
        //     name: 'customerTradeName',
        //     type: FieldType.string,
        //     label: intl.get('dji.otc.om.view.field.tagTypeB').d('交易身份名称'),
        //     required: true,
        // },
        // {
        //     name: 'applicableDimensionCode',
        //     type: FieldType.string,
        //     label: intl.get('dji.otc.om.view.field.tagName').d('适用维度'),
        //     required: true,
        //     lookupCode: 'DJIOM.APPLICABLE_DIMENSION',
        // },
        // {
        //     name: 'customerTradeEnable',
        //     type: FieldType.string,
        //     label: intl.get('dji.otc.om.view.field.tagName').d('交易身份状态'),
        //     required: true,
        //     lookupCode: 'DJIDLR_ENABLE',
        // },
        {
            name: 'customerGroupToken',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerGroupToken').d('组别客户编码'),
        },
        {
            name: 'customerGroupName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerGroupName').d('组别客户名称'),
        },
        {
            name: 'customerTrulyToken',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerTrulyToken').d('客户编码'),
        },
        {
            name: 'customerTrulyName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerTrulyName').d('客户注册名'),
        },
        {
            name: 'customerTrulyTransactionName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerTrulyTransactionName').d('客户简称'),
        },
        {
            name: 'customerGroupEnable',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerGroupEnable').d('客户状态'),
            lookupCode: 'DJIDLR_ENABLE',
        },
    ],
    queryFields: [
        {
            name: 'customerTrulyName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerTrulyName').d('注册客户'),
        },
        {
            name: 'groupId',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
            lookupCode: 'DJICM_GROUP',
        },
        {
            name: 'name',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.groupCustomerName').d('组别客户'),
            // options: customerOptions,
            // textField: 'name',
            // valueField: 'id',
        },
        {
            name: 'state',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.customerStatus').d('客户状态'),
            lookupCode: 'DJIDLR_ENABLE',
            defaultValue: 'ACTIVE'
        },
        // {
        //     name: 'area',
        //     type: FieldType.string,
        //     label: '区域',
        //     options: areaOptions,
        //     textField: 'regionName',
        //     valueField: 'regionId',
        // },
    ],
});

export { customerOrderAttributeListDS };
